<template>
	<view class="app-container bg-color">
		<view v-for="(element,index) in layoutData" :key="index">
			<mall-nav-bar v-if="element.code === 'mall_title'" :metadata="element.metadata"></mall-nav-bar>
			<search-input-fake v-if="element.code === 'mall_search_input'"></search-input-fake>
			<index-swiper :metadata="element.metadata" class="index-swiper"
				v-if="element.code === 'mall_banner'"></index-swiper>
			<index-fun-module :metadata="element.metadata" v-if="element.code === 'mall_menu'"></index-fun-module>
			<index-seckill v-if="element.code === 'mall_seckill'" class="seckill"></index-seckill>
			<commodity-list ref="productList" v-if="element.code === 'mall_hot_product'"></commodity-list>
		</view>
		<tabbar-top></tabbar-top>
	</view>
</template>

<script>
	import MallNavBar from '@/components/index/MallNavbar.vue'
	import indexSwiper from '@/components/index/indexSwiper.vue'
	import indexFunModule from '@/components/index/indexFunModule.vue'
	import indexSeckill from '@/components/index/indexSeckill.vue'
	import CommodityList from '@/components/common/CommodityList.vue'
	import searchInputFake from '@/components/index/searchInputFake.vue'
	import TabbarTop from '@/components/common/TabbarTop.vue'
	import $http from '../../common/api/request.js'
	export default {
		components: {
			indexSwiper,
			indexFunModule,
			indexSeckill,
			CommodityList,
			searchInputFake,
			TabbarTop,
			MallNavBar
		},
		data() {
			return {
				layoutData: []
			}
		},
		onReachBottom() {
			let productComponentList = this.$refs.productList
			productComponentList.forEach(item => {
				item.queryParams.pageNo += 1
				item.listData()
			})
		},
		onShow() {
			this.loadData()
		},
		methods: {
			loadData() {
				$http.request({
					url: '/webapp/layout/list'
				}).then(res => {
					if (res.success) {
						this.layoutData = res.data
						let titleData = this.layoutData.find(item => item.code === 'mall_title')
						if (titleData) {
							uni.setNavigationBarTitle({
								title: titleData.metadata.title
							})
						}
					}
				})
			}
		}
	}
</script>

<style scoped>
	.app-container {
		position: absolute;
		left: 0;
		top: 0;
		right: 0;
		bottom: 0;
		width: 100%;
		height: 100%;
		background: linear-gradient(#F43226 80rpx, white 45%);
	}
</style>